package com.bao.system.mapper;

import com.bao.system.entity.Department;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author bao
 * @since 2021-06-04
 */
@Repository
public interface DepartmentMapper extends BaseMapper<Department> {

    @Select("select d.id, d.name, ifnull((select count(*) from tb_user u " +
            "where u.department_id = d.id and u.deleted = 0 group by department_id), 0) " +
            "as deptCount " +
            "from tb_department d")
    List<Department> findDeptAndCount();

}
